﻿using System.IO;
using System.Linq;
using System.Text;

namespace ShareHelper
{
    /// <summary>
    /// 路径过滤
    /// </summary>
    public static class PathEx
    {
        /// <summary>
        /// 无效文件名称字符
        /// </summary>
        private static string[] InvalidName { get; }

        static PathEx()
        {
            InvalidName = Path.GetInvalidFileNameChars().Select(a => a.ToString()).ToArray();
        }

        /// <summary>
        /// 过滤文件名称非法字符
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static string GetFileName(this string name)
        {
            StringBuilder FileName = new StringBuilder(name);
            foreach (var item in InvalidName) FileName.Replace(item, null);
            return FileName.ToString();
        }
    }
}